﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace DbWord.Request
{
    /// <summary>
    /// MS SQL Server
    /// </summary>
    class Msql:Idb
    {
        static string Connstr = ConfigurationManager.ConnectionStrings["DbConnection"].ConnectionString;

        public string ExecuteScalar(string sql)
        {
            object o = null;

            using (SqlConnection conn = new SqlConnection(Connstr))
            using (SqlCommand exec = new SqlCommand(sql, conn))
            {
                conn.Open();
                o = exec.ExecuteScalar();
                conn.Close();
            }
            if (o != null)
                return o.ToString();
            else return string.Empty;
        }

        public DataTable FillTable(string sql)
        {
            DataTable tb = new DataTable();

            using (SqlConnection conn = new SqlConnection(Connstr))
            using (SqlDataAdapter da = new SqlDataAdapter(sql, conn))
            {
                da.Fill(tb);
            }

            return tb;
        }
    }
}
